#!/usr/bin/env bash

# ----------------------------------------------------------------------
# Filename:   04-rpcbind111-master.sh
# Version:    1.0
# Date:       2020/05/18
# Author:     Lz
# Email:      lz843723683@gmail.com
# History：     
#             Version 1.0, 2020/05/18
# Function:   关闭111端口
# Out:        
#              0 => TPASS
#              1 => TFAIL
#              other=> TCONF
# ----------------------------------------------------------------------

## TODO : 测试收尾清除工作
#
Rpcbind111Clean_FTGW_MASTER(){
	return $TPASS
}


## TODO: 调用程序退出函数
#    In: $1 => 调用脚本结果值
Rpcbind111Exit_FTGW_MASTER(){
        # 调用退出函数，其中调用了clean相关函数
	Exit_FTLIB ${1}
}


## TODO: 用户界面
#
Rpcbind111USAGE_FTGW_MASTER(){
	USAGE_FTLIB "金风主控版 - 关闭111端口"
}


## TODO : 测试前的初始化 
#  Out  : 
#         0 => TPASS
#         1 => TFAIL
#         other=> TCONF
Rpcbind111Init_FTGW_MASTER(){
        # 调用初始化函数
	Init_FTLIB "Rpcbind111Clean_FTGW_MASTER"
        # 调用用户界面函数
 	Rpcbind111USAGE_FTGW_MASTER
}


## TODO ：关闭111端口
#
Rpcbind111Test01_FTGW_MASTER(){
        local svcname="rpcbind"

	# 当前服务已关闭
	SvcActive_FTLIB "noActive" "no" "$svcname"
        RetParse_FTLIB "要求关闭服务: $svcname" "False"

	# 关闭服务自启动
	SvcEnable_FTLIB "noEnable" "no" "$svcname"
        RetParse_FTLIB "要求服务未自启动: $svcname" "False"

	# 关闭端口111,最后留空格
	local port=":111 "
	echo "netstat -nultp | grep $port"
	netstat -nultp | grep $port
	if [ $? -eq 0 ];then
		# 端口已经打开
		OutputRet_FTLIB "$TFAIL"
		RetParse_FTLIB "要求关闭111端口" "False"
	else
		# 端口已经关闭
		echo "未打开111端口"
		OutputRet_FTLIB "$TPASS"
		RetParse_FTLIB "要求关闭111端口" "False"
	fi
}


## TODO : Main
#  Out  : 
#         0 => TPASS
#         1 => TFAIL
#         other => TCONF
Rpcbind111Main_FTGW_MASTER(){
	Rpcbind111Init_FTGW_MASTER

	Rpcbind111Test01_FTGW_MASTER

	return ${TPASS}	
}

Rpcbind111Main_FTGW_MASTER
Rpcbind111Exit_FTGW_MASTER $?
